package com.taotao.service.impl;

import com.taotao.mapper.TbItemCatMapper;
import com.taotao.pojo.EasyUITreeNode;
import com.taotao.pojo.TbItemCat;
import com.taotao.pojo.TbItemCatExample;
import com.taotao.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ItemCatServiceImpl implements ItemCatService {
    @Autowired
    private TbItemCatMapper catMapper;
    @Override
    public List<EasyUITreeNode> getItemCat(Long parentId) {
        TbItemCatExample catExample = new TbItemCatExample();
        TbItemCatExample.Criteria criteria = catExample.createCriteria();
        criteria.andParentIdEqualTo(parentId);
        List<TbItemCat> tbItemCats = catMapper.selectByExample(catExample);
        List<EasyUITreeNode> resultList = new ArrayList<>();
        for (TbItemCat tbItem:tbItemCats) {
            EasyUITreeNode treeNode = new EasyUITreeNode();
            treeNode.setId(tbItem.getId());
            treeNode.setText(tbItem.getName());
            treeNode.setState(tbItem.getIsParent()?"closed":"open");
            resultList.add(treeNode);
        }
        return resultList;
    }
}
